package com.summer.es.controller;


import com.summer.es.dto.SearchPageResultDto;
import com.summer.es.po.CoursePublish;
import com.summer.es.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "课程搜索API")
@RestController
@Slf4j
public class SearchController {

    @Autowired
    private SearchService searchService;

    @ApiOperation("分页搜索发布课程")
    @GetMapping("/course/list")
    public SearchPageResultDto<CoursePublish> getCoursePublish(int pageNo, int pageSize, String keywords){
        log.info("pageNo = {}, pageSize = {}, keywords = {}", pageNo, pageSize, keywords);
        return searchService.getCoursePublishList(pageNo, pageSize, keywords);
    }


    @ApiOperation("发布课程数据同步到es")
    @PostMapping("/course/add")
    public boolean insert2es(@RequestBody CoursePublish coursePublish){
        searchService.insert2es(coursePublish);
        // 没有出现异常就返回true
        return true;
    }

}
